package com.fyt.ZhongYaoApp.Controller;

import com.fyt.ZhongYaoApp.pojo.Result;
import com.fyt.ZhongYaoApp.pojo.ShoppingCar;
import com.fyt.ZhongYaoApp.pojo.dto.ShoppingCarDTO;
import com.fyt.ZhongYaoApp.service.ShoppingCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/ShoppingCar")
public class ShoppingCarController {

    @Autowired
    private ShoppingCarService shoppingCarService;

    @PostMapping("/add")// 添加
    public Result add(@RequestBody ShoppingCarDTO shoppingCarDTO){

        shoppingCarService.addCar(shoppingCarDTO);
        return Result.success("添加成功");
    }

    @GetMapping("/show")// 查看
    public Result<List<ShoppingCar>> list(){

        List<ShoppingCar> list = shoppingCarService.showShoppingCar();
        return Result.success(list);
    }

    @PostMapping("/clean")
    public Result clean(){
        shoppingCarService.cleanShoppingCar();
        return Result.success("购物车已清空");
    }
}
